package com.example.demo.util;

import com.example.demo.config.ThreadContext;
import org.slf4j.MDC;
import org.slf4j.helpers.BasicMDCAdapter;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryUtils;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author: fanfan
 * @Date: 2019/3/16 23:53
 * @Description
 */
public class TraceUtil {
    public static void traceStart() {

        ThreadContext.init();
        String traceId = generateTraceId();
//        MDCHelper.put("traceId", traceId);
//        ThreadContext.putTraceId(traceId);
    }

    public static void traceEnd() {
        MDC.clear();
        ThreadContext.clean();
    }

    /**
     * 生成跟踪ID
     *
     * @return
     */
    public static String generateTraceId() {
        return UUID.randomUUID().toString();
    }
}